<script type="text/javascript">
$(function(){
	var pg = App.codex.scanIndex.ui, pp = pg.params || {}
		, hd = pg.children('.head'), bd = pg.children('.body');
	
	var frm = pg.frm = {
		url: pg.seek('url'),
		branch: pg.seek('branch'),
		target: pg.seek('target'),
		path: pg.seek('path')
	};
	
	frm.target.mac('combo', {
		keyField: 'key',
		displayField: 'value',
		width: 600,
		boxWidth: 600,
		data: [{
			key: 'local', value: 'local'
		}, {
			key: 'server', value: 'server'
		}],
		onSelect: function(me, sk, sd){
			var r = sd[0] || {};
			if (r.key == 'local') {
				frm.url.attr('disabled', true);
				frm.branch.attr('disabled', true);
				frm.path.removeAttr('disabled');
			} else {
				frm.url.removeAttr('disabled');
				frm.branch.removeAttr('disabled');
				frm.path.attr('disabled', true);
			}
		}
	}).val('local');

	function getValues(){
		return {
			url: frm.url.val(),
			branch: frm.branch.val(),
			path: frm.path.val(),
			target: frm.target.val()
		};
	}
	function setValues(o){
		frm.path.val(o.path);
	}
	function validate(p){
// 		var m = pg.seek('msg').html(''), v = App.auth.validation, x = App.validate;
// 		return x(v.func.code, p.code, m, '功能编号') &&
// 			x(v.func.name, p.name, m, '功能名称') &&
// 			x(v.func.status, p.status, m, '状态');
		return true;
	}

	pg.seek('ok').click(function(){
		var pms = getValues();
		if (!validate(pms)) {
			return;
		}
		mac.confirm('确定要扫描此代码吗？', function(){
			$.post(App.codex.ctx + '/scan/'//
					+ pms.target + '.do', pms, function(rs){
				var ro = mac.eval(rs);
				if (ro.success) {
					mac.alert('扫描成功');
				} else {
					pg.seek('msg').html(mac.msg(ro.data, ro.params));
				}
			});
		});
		return false;
	});
});
</script>
<div class="head">
	<div>
		<div class="title">代码扫描</div>
	</div>
	<div class="clear"></div>
</div>
<div class="clear"></div>
<div class="body">
<div class="form">
	<div class="item">
		<div class="label">目标地址</div>
		<div>
			<div class="combo fl" name="target"></div>
		</div>
		<div class="clear"></div>
	</div>
	<div class="item">
		<div class="label">GIT URL</div>
		<div>
			<input type="text" name="url" />
		</div>
		<div class="clear"></div>
	</div>
	<div class="item">
		<div class="label">分支</div>
		<div>
			<input type="text" name="branch" />
		</div>
		<div class="clear"></div>
	</div>
	<div class="item">
		<div class="label">扫描目录</div>
		<div>
			<input type="text" name="path" />
		</div>
		<div class="clear"></div>
	</div>
	<div class="bottom">
		<button name="ok">提交</button>
	</div>
	<div class="clear"></div>
</div>
<div class="clear"></div>